package com.example.demo02.utils;

import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class PageUtils {
    public static <T,R>PageInfo<R> mapping(PageInfo<T> pageInfo, Function<T,R> mapper){
        //master new 1
        //mater new 2
        //master new 3
        List<T> list = pageInfo.getList();
        //master new 4
        //master new 5
        List<R> collect = list.stream().map(mapper).collect(Collectors.toList());
        PageInfo<R> info = PageInfo.of(collect);
        info.setPageNum(pageInfo.getPageNum());
        info.setTotal(pageInfo.getTotal());
        //master new 6
        return info;
    }
}
